//敌军类
function EnemyModel(x,y,width,height,type,blood,speed,sumStatus){
//	敌人的坐标
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
	
	//敌人的图片
	this.img = new Image;
	this.img.src = "img/" + type + ".png";
	
	//血量
	this.blood = blood;
	//移动速度
	this.speed = speed;
	
	//敌人的类型
	this.type = type;
	//死亡
	this.isDie = false;
	//飞机的状态
	this.status = 0;
	
	//用来记录飞机总的变化状态数量
	this.sumStatus = sumStatus;
	
}
//随机 min——max 之内的整数
function randNumber(min,max){
	return parseInt(Math.random() * (max - min + 1) + min);
}

function EnemyControllerClass(){
	//创建保存敌人的数组
	this.enemyArray = [];
	//创建显示敌人
	this.createShowEnemy = function(){
		var num = randNumber(1,200);
		// 敌人1
		if(num > 20 && num < 30){
			var enemy1 = new EnemyModel(randNumber(0,canvas.width - 38),-34,38,34,"enemy1",1,randNumber(2,4),5);
			this.enemyArray.push(enemy1);
		}
		// 敌人2
		if (num == 10) {
			var enmey2 = new EnemyModel(randNumber(0,canvas.width - 110),-164,110,164,"enemy2",7,1,10);
		this.enemyArray.push(enmey2);
		}
		
		// 敌人3
		if (num == 14) {
			var enmey3 = new EnemyModel(randNumber(0,canvas.width - 46),-64,46,64,"enemy3",3,randNumber(1,3),6);
			this.enemyArray.push(enmey3);
		}
		
		//让敌人动起来
		
		for(var i = 0;i < this.enemyArray.length;i++){
			if (this.enemyArray[i].y > canvas.height) {
				this.enemyArray.splice(i,1);
				continue;
			}
			if (this.enemyArray.isDie) {
				this.enemyArray[i].status++;
				if (this.enemyArray[i].status > this.enemyArray[i].sumStatus) {
					//消失，移除
					this.enemyArray.splice(i,1);
					continue;
				}
			}else{
				// 增加敌人的 y 值，让敌人位置发生变化
				this.enemyArray[i].y += this.enemyArray[i].speed;
			}
			// 绘制敌人
			context.beginPath();
			context.drawImage(this.enemyArray[i].img,this.enemyArray[i].status * this.enemyArray[i].width,0,this.enemyArray[i].width,this.enemyArray[i].height,this.enemyArray[i].x,this.enemyArray[i].y,this.enemyArray[i].width,this.enemyArray[i].height);
			context.save();
			
		}
	}
}

